package com.cbgolf.oa.util;

import java.util.List;
import java.util.Map;

/**
 * Created by lq on 2017/10/18.
 */

public class CollectionUtil {

  public static void clear(List<? extends Object> list) {
    if (!Util.listIsNull(list)) {
      list.clear();
    }
  }

  public static boolean mapIsNull(Map<? extends Object, ? extends Object> map) {
    return (null == map || map.isEmpty() || map.size() == 0);
  }

  public static String getString(List<String> list, int position) {
    try {
      if (!Util.listIsNull(list) && position < list.size()) {
        return TextUtil.Text(list.get(position));
      }
    } catch (Exception e) {
    }
    return "";
  }

  public static boolean arrayIsNull(Object[] objs) {
    return (null == objs || objs.length == 0);
  }


  public static boolean getMapBoolean(Map<Integer, Boolean> map, Integer key) {
    return (!mapIsNull(map) && map.containsKey(key) && null != map.get(key)
        && map.get(key));
  }

  public static String getMapString(Map<Integer, String> map, int key) {
    try {
      return map.get(key);
    } catch (Exception e) {
      return null;
    }
  }

  public static int getMapInt(Map<String, Integer> map, String key) {
    try {
      return TypeUtil.getInt(map.get(key));
    } catch (Exception e) {
      return 0;
    }
  }

  public static String getMapString(Map<String, String> map, String key) {
    try {
      return map.get(key);
    } catch (Exception e) {
      return null;
    }
  }
}
